package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.OrderPurchase;
import com.sumi.erp.service.IOrderPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购单主Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/erp/purchase")
public class OrderPurchaseController extends BaseController
{
    @Autowired
    private IOrderPurchaseService orderPurchaseService;

    /**
     * 查询采购单主列表
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderPurchase orderPurchase)
    {
        startPage();
        List<OrderPurchase> list = orderPurchaseService.selectOrderPurchaseList(orderPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购单主列表
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:export')")
    @Log(title = "采购单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderPurchase orderPurchase)
    {
        List<OrderPurchase> list = orderPurchaseService.selectOrderPurchaseList(orderPurchase);
        ExcelUtil<OrderPurchase> util = new ExcelUtil<OrderPurchase>(OrderPurchase.class);
        util.exportExcel(response, list, "采购单主数据");
    }

    /**
     * 获取采购单主详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderPurchaseService.selectOrderPurchaseById(id));
    }

    /**
     * 新增采购单主
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:add')")
    @Log(title = "采购单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPurchase orderPurchase)
    {
        return toAjax(orderPurchaseService.insertOrderPurchase(orderPurchase));
    }

    /**
     * 修改采购单主
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:edit')")
    @Log(title = "采购单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPurchase orderPurchase)
    {
        return toAjax(orderPurchaseService.updateOrderPurchase(orderPurchase));
    }

    /**
     * 删除采购单主
     */
    @PreAuthorize("@ss.hasPermi('erp:purchase:remove')")
    @Log(title = "采购单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderPurchaseService.deleteOrderPurchaseByIds(ids));
    }
}
